<template>
  <div class="container">
    <div class="header clearfix">您的反馈对我们非常重要，如有任何意见、问题请及时反馈我们，以便为您提供更好的服务!</div>
    <div class="type">
      <div class="title">反馈类型</div>
      <ul class="type-list clearfix">
        <li class="type-item"
            :class="{'active':item.type==type}"
            v-for="(item, index) in type_arr"
            :key="index"
            @tap="change_type(item)">{{item.name}}</li>
      </ul>
    </div>
    <div class="evaluat">
      <div class="title">描述</div>
      <div class="content">
        <textarea v-if="showarea"
                  @blur="change_status(false)"
                  :fixed="true"
                  @input="changeeva()"
                  v-model="eva_content"
                  maxlength="255"
                  class="textarea"
                  placeholder="您有任何疑问都可反馈告诉我们，期待您的建议，以便我们更好的改进～"></textarea>
        <div class="textarea"
             v-else
             @tap="change_status(true)">{{eva_content==''?'':eva_content}}</div>
        <div class="tip">{{max_length}}字</div>
      </div>
    </div>
    <picupload :picture_num="3"
               v-on:getmsg="hasmsg"></picupload>
    <div class="sub-btn"
         @tap="sub_eva()">提交</div>
  </div>
</template>

<script>
import common from "@/assets/js/mmk_common.js";
import picupload from "@/components/pic_upload/pic_upload";
export default {
  data () {
    return {
      showarea: true,
      max_length: 255,
      eva_content: "",
      image_arr: [],
      baseUrl: common.image_response,
      type_arr: [
        {
          name: "服务建议",
          active: false,
          type: 1
        },
        {
          name: "问题投诉",
          active: false,
          type: 2
        },
        {
          name: "系统反馈",
          active: false,
          type: 3
        },
        {
          name: "其他",
          active: false,
          type: 4
        }
      ],
      type: ""
    };
  },
  onLoad () {
    wx.setNavigationBarTitle({
      title: "意见反馈"
    });
    Object.assign(this.$data, this.$options.data());
  },
  components: {
    picupload
  },
  methods: {
    change_status (status) {
      this.showarea = status;
    },
    changeeva () {
      this.max_length = 255 - this.eva_content.length;
    },
    change_type (item) {
      this.type = item.type;
    },
    hasmsg (msg) {
      this.image_arr = msg;
    },
    sub_eva () {
      if (this.type == "") {
        wx.showToast({
          title: "请选择反馈类型", //提示的内容,
          icon: "none", //图标,
          duration: 1500, //延迟时间,
          mask: false //显示透明蒙层，防止触摸穿透,
        });
        return false;
      } else if (this.eva_content.trim() == "") {
        wx.showToast({
          title: "请输入反馈内容", //提示的内容,
          icon: "none", //图标,
          duration: 1500, //延迟时间,
          mask: false, //显示透明蒙层，防止触摸穿透,
          success: res => { }
        });
        return false;
      } else if (this.eva_content.length < 15) {
        wx.showToast({
          title: "不能少于15字", //提示的内容,
          icon: "none", //图标,
          duration: 1500, //延迟时间,
          mask: false, //显示透明蒙层，防止触摸穿透,
          success: res => { }
        });
        return false;
      } else {
        wx.showLoading({
          title: "提交中...", //提示的内容,
          mask: true, //显示透明蒙层，防止触摸穿透,
          success: res => { }
        });
        common.fly_post(
          "api/v4_2/user_feedback/index",
          {
            type: this.type,
            content: this.eva_content,
            pic: this.image_arr.join(",")
          },
          result => {
            wx.hideLoading();
            let res = result.data;
            if (res.status_code == 0) {
              wx.showToast({
                title: "提交成功，感谢您的反馈", //提示的内容,
                icon: "none", //图标,
                duration: 1500, //延迟时间,
                mask: true, //显示透明蒙层，防止触摸穿透,
                success: res => {
                  setTimeout(() => {
                    wx.navigateBack({
                      delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
                    });
                  }, 1500);
                }
              });
            } else {
              wx.showToast({
                title: res.message,
                icon: "none",
                duration: 2000,
                mask: false
              });
            }
          }
        );
      }
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  height: 100%;
  background: rgba(243, 244, 246, 1);
  .header {
    width: 100%;
    font-size: 12px;
    font-family: "PingFangSC-Regular";
    font-weight: 400;
    color: rgba(102, 102, 102, 1);
    padding: 15px;
    box-sizing: border-box;
  }
  .type {
    background-color: #fff;
    padding: 15px;
    box-sizing: border-box;
    .title {
      font-size: 14px;
      font-family: "Medium";
      font-weight: 500;
      color: rgba(51, 51, 51, 1);
      font-weight: bold;
    }
    .type-list {
      margin-top: 10px;
      display: flex;
      justify-content: space-between;
      .type-item {
        width: 76px;
        height: 24px;
        border: 1px solid rgba(102, 102, 102, 1);
        text-align: center;
        font-size: 14px;
        font-family: "PingFangSC-Regular";
        font-weight: 400;
        color: rgba(51, 51, 51, 1);
        line-height: 24px;
      }
      .active {
        border: 1px solid rgba(255, 56, 62, 1);
        color: rgba(255, 56, 62, 1);
      }
    }
  }
  .evaluat {
    height: 180px;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0px 1px 0px 0px rgba(204, 204, 204, 0.5);
    margin-top: 10px;
    .title {
      line-height: 44px;
      padding-left: 15px;
      font-size: 14px;
      font-family: "PingFangSC-Regular";
      font-weight: 400;
      color: rgba(102, 102, 102, 1);
    }
    .content {
      width: 345px;
      height: 120px;
      background: rgba(251, 251, 251, 1);
      margin: 0 auto;
      position: relative;
      .textarea {
        width: 100%;
        height: 100%;
        background: rgba(245, 245, 245, 1);
        display: block;
        padding: 8px 10px;
        font-size: 14px;
        font-family: "PingFangSC-Regular";
        box-sizing: border-box;
      }
      .tip {
        font-size: 10px;
        font-family: "PingFangSC-Regular";
        font-weight: 400;
        color: rgba(136, 136, 136, 1);
        position: absolute;
        bottom: 10px;
        right: 10px;
      }
    }
  }
  .sub-btn {
    width: 100%;
    height: 50px;
    background: rgba(246, 70, 101, 1);
    font-size: 17px;
    font-family: "Medium";
    font-weight: 500;
    line-height: 50px;
    text-align: center;
    color: rgba(255, 255, 255, 1);
    position: fixed;
    bottom: 0;
    left: 0;
  }
}
</style>
